package org.example.ch06;

/**
 * @author yang
 * @date 2024-03-21
 */
public class MyThread extends Thread{
    private static int money = 5000 ;
    private int getMoney = 0;

    public MyThread(int getMoney) {
        this.getMoney = getMoney;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"取出"+this.getMoney+"元");
        synchronized (MyThread.class){
            if (money-getMoney<0){
                System.out.println(Thread.currentThread().getName()+"取钱失败,余额不足");
            }else{
                money -= getMoney;
                System.out.println(Thread.currentThread().getName()+"取钱成功,余额剩余"+money+"元");
            }
        }
    }
}
